import { createApp } from 'vue'
import { createPinia } from 'pinia'
import axios from 'axios'
import router from './router'
import './style.css'
import App from './App.vue'

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)

// 响应拦截器，处理token过期等情况
axios.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
    if (error.response && error.response.status === 401) {
      // 延迟导入authStore以避免循环引用
      import('./store/auth').then(({ authStore }) => {
        const auth = authStore();
        auth.logout();
        router.push({ name: 'login' });
      });
    }
    return Promise.reject(error);
  }
);

app.mount('#app')
